// ResourceBundle.cpp: implementation of the CResourceBundle class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ResourceBundle.h"
#include "XmlMarkup.h"
#include "FileUtils.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CResourceBundle::CResourceBundle()
{
	m_strResFile = _T("XSPhoneUI.xml");
}

CResourceBundle::~CResourceBundle()
{

}

void CResourceBundle::SetResouceFile(const char* szResFile)
{
	if (strcmp(szResFile,"") != 0)
	{
		m_strResFile = szResFile;
	}
}

CString CResourceBundle::GetResouceString(const char* szResID)
{
	CString strRetVal = _T("");

	// TODO: Add your specialized code here and/or call the base class
	CXmlMarkup myXmlMarkup;
	
	// Get xml file direction
	CString istrResFile = _T("");
	LPTSTR p = istrResFile.GetBufferSetLength(_MAX_PATH);
	GetModuleFileName(AfxGetApp()->m_hInstance,p,_MAX_PATH);
	istrResFile.ReleaseBuffer();
	istrResFile = istrResFile.Left(istrResFile.ReverseFind('\\')+1);
	istrResFile += m_strResFile;
	
	// Read Resource File
	CFileUtils myFileUtils;
	
	if (myFileUtils.FileExist(istrResFile))
	{
		myXmlMarkup.Load(istrResFile);
		myXmlMarkup.ResetPos();
		myXmlMarkup.FindElem("XSPHONEUI");
		myXmlMarkup.IntoElem();

		if (myXmlMarkup.FindElem(szResID))
		{
			strRetVal = myXmlMarkup.GetAttrib("value");
		}
	}

	return strRetVal;
}
